package org.hchdubbo.consumer;

import org.I0Itec.zkclient.ZkClient;
import org.hchdubbo.consumer.entity.ZkApplicationConfig;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Author: HeCongHui
 * @Time :2021/12/15 11:03
 */
public class ServiceDiscover {
    @Autowired
    private ZkApplicationConfig zkApplicationConfig;

    private ZkClient zkClient;


    private String rootNamePath = "/hchdubbo";

    public ServiceDiscover() {
        // 1. 连接zk连接
        zkClient = new ZkClient(zkApplicationConfig.getZkServers(), zkApplicationConfig.getConnectionTimeout());
    }


    public List<String> getDiscover(String serviceName) {
        List<String> children = zkClient.getChildren(rootNamePath + "/" + serviceName + "/providers");
        return children;
    }

}